//index.js
const app = getApp()

Page({
  data: {
    img: [{
      img: 'https://sd.offcn.com/zg/wximg/2021/guoshengkao/newban.jpg',
      bind: 'newban'
    }],
    navbarArr: [{
        pic_url: 'https://sd.offcn.com/zg/wximg/2022/ky/welcome/kyzl.png',
        viewNavto: 'icon1',
        name: '一研为定'
      },
      {
        pic_url: 'https://sd.offcn.com/zg/wximg/2022/ky/welcome/zyjsk.png',
        viewNavto: 'icon2',
        name: '专业检索库'
      },
      {
        pic_url: 'https://sd.offcn.com/zg/wximg/2022/ky/welcome/jsbb.png',
        viewNavto: 'icon3',
        name: '论文查重券'
      },
      {
        pic_url: 'https://sd.offcn.com/zg/wximg/2022/ky/welcome/zjyy.png',
        viewNavto: 'icon4',
        name: '调研问卷'
      },
      {
        pic_url: 'https://sd.offcn.com/zg/wximg/2022/ky/welcome/fsxcx.png',
        viewNavto: 'icon5',
        name: '重要讲话'
      },
      {
        pic_url: 'https://sd.offcn.com/zg/wximg/2022/ky/welcome/wklq.png',
        viewNavto: 'icon6',
        name: '面试金句'
      },
      // {
      //   pic_url: 'http://sd.offcn.com/zg/wximg/2021/sk/index/icon7.png',
      //   viewNavto: 'icon7',
      //   name: '热点素材'
      // },
      // {
      //   pic_url: 'http://sd.offcn.com/zg/wximg/2021/sk/index/icon8.png',
      //   viewNavto: 'icon8',
      //   name: '面试考情'
      // },
    ],
    theSwiper: [{
        src: 'http://sd.offcn.com/zg/wximg/gkhz-img/new.jpg',
        tomini: 'tozx'
      },
      {
        src: 'http://sd.offcn.com/zg/wximg/gkhz-img/banner_2.jpg',
        tomini: 'tozx'
      },
      {
        src: 'http://sd.offcn.com/zg/wximg/gkhz-img/banner_3.jpg',
        tomini: 'togkbs'
      },
      {
        src: 'http://sd.offcn.com/zg/wximg/gkhz-img/banner_4.jpg',
        tomini: 'to19'
      }
    ],
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    interval: 3000,
    duration: 1500,
    current: 0,
    area: '默认',
    geneal: '默认'
  },
  banner1: function () {
    wx.navigateTo({
      url: '../out/skmdm/skmdm',
    })
  },
  banner2: function () {
    wx.navigateToMiniProgram({
      appId: 'wxca86930ec3e80717',
      path: 'page/course/details?scode=&id=359751',
      envVersion: 'release', // 打开正式版

    })
  },
  banner3: function () {
    wx.navigateTo({
      url: '../out/skbs/skbs',
    })
  },
  newban: function () {
    wx.navigateTo({
      url: '../out/banner1/banner1',
    })
  },
  icon1: function () {
    var _ = this;
    var area = wx.getStorageSync('area')
    var agent = wx.getStorageSync('agent')
    var page = wx.getStorageSync('page')

    wx.navigateTo({
      url: '../login_st/login_st?area=' + area + '&agent=' + agent + '&page=' + page,
    })
  },
  icon2: function () {
    var _ = this;
    var area = wx.getStorageSync('area')
    var agent = wx.getStorageSync('agent')
    var page = wx.getStorageSync('page')
    wx.navigateTo({
      url: '../zyjsk/index/index?area=' + area + '&agent=' + agent + '&page=' + page
    })
  },
  icon3: function () {
    var _ = this;
    var area = wx.getStorageSync('area')
    var agent = wx.getStorageSync('agent')
    var page = wx.getStorageSync('page')
    wx.navigateTo({
      url: '../ziliao/jsb/login/login?area=' + area + '&agent=' + agent + '&page=' + page
    })
  },
  icon4: function () {
    var _ = this;
    var area = wx.getStorageSync('area')
    var agent = wx.getStorageSync('agent')
    var page = wx.getStorageSync('page')
    wx.navigateTo({
      url: '../jzyy/jzyy?area=' + area + '&agent=' + agent + '&page=' + page
    })
  },
  icon5: function () {
    var _ = this;
    var area = wx.getStorageSync('area')
    var agent = wx.getStorageSync('agent')
    var page = wx.getStorageSync('page')
    wx.navigateTo({
      url: '../fsfsx/index/index?area=' + area + '&agent=' + agent + '&page=' + page
    })
  },
  icon6: function () {
    var _ = this;
    var area = wx.getStorageSync('area')
    var agent = wx.getStorageSync('agent')
    var page = wx.getStorageSync('page')
    wx.navigateTo({
      url: '../kyyq/index/index?area=' + area + '&agent=' + agent + '&page=' + page
    })
  },
  icon7: function () {
    var _ = this;
    var area = wx.getStorageSync('area')
    var agent = wx.getStorageSync('agent')
    var page = wx.getStorageSync('page')
    wx.navigateTo({
      url: '../booklist/booslist?area=' + area + '&agent=' + agent + '&page=' + page
    })
  },
  icon8: function () {
    var area = wx.getStorageSync('area')
    var agent = wx.getStorageSync('agent')
    var page = wx.getStorageSync('page')

    wx.navigateTo({
      url: '../booklist/booslist?area=' + area + '&agent=' + agent + '&page=' + page
    })
  },
  link1: function () {
    var _ = this;
    var area = wx.getStorageSync('area')
    var agent = wx.getStorageSync('agent')
    var page = wx.getStorageSync('page')
    wx.navigateToMiniProgram({
      appId: 'wxca86930ec3e80717', //国考职位查询小程序appid
      path: 'page/course/details?id=359751',
      envVersion: 'release', //develop（开发版），trial（体验版），release（正式版） 
      success(res) {
        console.log('打开成功！')
      }
    })
  },
  link2: function () {
    wx.navigateToMiniProgram({
      appId: 'wxca86930ec3e80717', //国考职位查询小程序appid
      path: 'page/course/details?id=359751',
      envVersion: 'release', //develop（开发版），trial（体验版），release（正式版） 
      success(res) {
        console.log('打开成功！')
      }
    })
  },
  link11: function () {
    wx.navigateTo({
      url: '../out/y1/y1'
    })
  },
  link12: function () {
    wx.navigateTo({
      url: '../out/y2/y2'
    })
  },
  link13: function () {
    wx.navigateTo({
      url: '../out/y3/y3'
    })
  },
  link14: function () {
    wx.navigateTo({
      url: '../out/y4/y4'
    })
  },


  toxiaoneng: function () {
    wx.navigateTo({
      url: '../xiaoneng/xiaoneng'
    })
  },
  toshijuan: function () {
    wx.navigateToMiniProgram({
      appId: 'wx3bfce5135e23ad3f', //国考职位查询小程序appid
      path: 'pages/search/search/search?area=' + _.data.area + '&agent=' + _.data.agent + '&page=' + _.data.page, //国考职位查询首页index
      envVersion: 'release', //develop（开发版），trial（体验版），release（正式版） 
      success(res) {
        console.log('打开成功！')
      }
    })
  },
  onLoad: function (options) {
    var _ = this;
    console.log(options);
    _.setData({
      area: options.area,
      geneal: options.agent,
      page: options.page
    })
    if (options.area) {
      wx.setStorageSync('area', options.area)
      wx.setStorageSync('agent', options.agent)
      wx.setStorageSync('page', options.page)
    }


    var d = new Date()
    _.setData({
      sheng: 29 - d.getDate()
    })
  },
  swiperChange: function (e) {
    var _ = this;
    if (e.detail.source == 'touch') {
      _.setData({
        current: e.detail.current,
      })
    }
  },
  getPhoneNumber(e) {
    var _ = this;
    wx.cloud.callFunction({
      name: 'getMobile',
      data: {
        weRunData: wx.cloud.CloudID(e.detail.cloudID),
      }
    }).then(res => {
      _.setData({
        mobile: res.result,
      })
      wx.setStorage({
        key: "phone",
        data: res.result
      })
      try {
        var value = wx.getStorageSync('phone')
        if (value) {
          this.setData({
            "navbarArr[0].opentype": 'false',
            "navbarArr[2].opentype": 'false',
            "navbarArr[3].opentype": 'false',
            "navbarArr[7].opentype": 'false',
          });
        }
      } catch (e) {
        // Do something when catch error
      }
      console.log(res.result)
      console.log('cloud phone get success!')
      wx.request({ //发送请求
        url: 'https://zg99.offcn.com/index/chaxun/register?actid=21474&callback=?', //接收url
        data: {
          phone: res.result,
          fenxiao: _.data.area,
          geneal: _.data.geneal,
        }, //接收参数
        success(res) {
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          }
          console.log('zg99 phone get success !')

        }
      })

      wx.redirectTo({
        url: '../index/index'
      })

    }).catch(err => {
      console.error(err);
    });



  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var _ = this;
    var area = wx.getStorageSync('area')
    var agent = wx.getStorageSync('agent')
    var page = wx.getStorageSync('page')
    return {
      title: '2022山东省研究生考试',
      path: 'pages/index/index?area=' + area + '&agent=' + agent + '&page=' + page
    }

  },
  /**分享到朋友圈*/
  onShareTimeline: function () {
    var _ = this;
    var area = wx.getStorageSync('area')
    var agent = wx.getStorageSync('agent')
    var page = wx.getStorageSync('page')
    return {
      title: '2022山东省研究生考试',
      path: 'pages/index/index?area=' + area + '&agent=' + agent + '&page=' + page
    }
  }


})